﻿using Autofac;
using System.Reflection;

namespace SH.Room.Read.API.MyAutoFac
{
    /// <summary>
    /// 反射加工厂设计模式
    /// </summary>
    public class RoomAutoFac : Autofac.Module
    {
        /// <summary>
        /// AutoFac 工厂
        /// </summary>
        /// <param name="builder"></param>
        protected override void Load(ContainerBuilder builder)
        {
            //通过反射的方式加载类库（程序集）
            var Rep = Assembly.Load("SH.Room.Infrastructure");
            var Ser = Assembly.Load("SH.Room.Application");
            //将程序集注入到AutoFac中
            builder.RegisterAssemblyTypes(Rep).Where(x => x.Name.EndsWith("Repository")).AsImplementedInterfaces();
            builder.RegisterAssemblyTypes(Ser).Where(x => x.Name.EndsWith( "Services")).AsImplementedInterfaces();

            

            base.Load(builder);
        }
    }
}
